// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { LineEdit } from "std-widgets.slint";


component Sub {
    in-out property <bool> condition: true;
    in property <bool> enabled: true;
    callback set-value(string);
    if condition : HorizontalLayout {
        LineEdit {
            accepted => {
                set-value(self.text);
            }
            placeholder-text: "Hello";
            enabled <=> root.enabled;
        }
        LineEdit {
            enabled <=> root.enabled;
        }
    }
}

component Sub2 {
    in property <bool> condition;
    in property <bool> enabled: true;
    callback focus-c();
    if !condition: VerticalLayout {
        if true: LineEdit {  enabled <=> root.enabled;  }
        if !condition: FocusScope {
            focus-changed-event => {
                focus-c();
            }
            enabled <=> root.enabled;
        }
    }
}

export component TestCase inherits Window {
    in-out property <bool> condition: true;

    out property <string> value;

    if condition: VerticalLayout {
        if true: Sub {
            set-value(v) => { value = v; condition = false; }
            condition: root.condition;
            enabled: root.condition;
        }

    }

    if true: Sub2 {
        condition: root.condition;
        focus-c() => { condition = true; }
        enabled: !root.condition;
    }

}

/*
```rust
let instance = TestCase::new().unwrap();
slint_testing::send_keyboard_string_sequence(&instance, "\t");
slint_testing::send_keyboard_string_sequence(&instance, "hophop\n");
assert_eq!(instance.get_value(), "hophop");
assert_eq!(instance.get_condition(), false);
slint_testing::send_keyboard_string_sequence(&instance, "a\n\tdd\t\t");
assert_eq!(instance.get_condition(), true);
slint_testing::send_keyboard_string_sequence(&instance, "\tblop\n\t");
assert_eq!(instance.get_value(), "blop");
```

*/
